import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/net/api/http_api.dart';
import 'package:ls_work/net/post_request.dart';
import 'package:ls_work/net/response/patrol/patrol_record_list_data.dart';

class PatrolRecordListViewModel extends BaseListViewModel<PatrolRecordListData>{
  PatrolRecordListViewModel(BuildContext context) : super(context);
  PatrolRecordModel _model = PatrolRecordModel();

  var nameLike = "";

  @override
  Future<List<PatrolRecordListData>> requestListData() async {
    return await _model.getRecordList(page, pageLength,nameLike: nameLike,date: startDateStr);
  }

  @override
  void onCreated() {
    super.onCreated();
    requestRefresh();
  }
}

class PatrolRecordModel extends BaseMvvmModel{
  @override
  void onCleared() {
  }

  Future<List<PatrolRecordListData>> getRecordList(int page,int rows,{String nameLike="",String date = ""}) async {
      var map = {
        "page":page,
        "rows":rows,
        "date":date,
        "nameLike":nameLike,
      };
      var data = await HttpGo.instance.postData(PatrolApi.patrolRecordList,data: map,options: PostRequest.urlencodedHeader);
      if('0'==data['code']){
        return ( (data['data']['rows'] as List?) ??[]).map((e) => PatrolRecordListData.fromJson(e)).toList();
      }else{
        throw data['msg'];
      }
  }
}